/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vale.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.vale.entity.ContactSite;
import org.vale.entity.ContactSitePK;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Stateless
public class ContactSiteDAO extends AbstractFacade<ContactSite, ContactSitePK> {

    @PersistenceContext(unitName = "ValeEsperarPU")
    private EntityManager entityManager;

    public ContactSiteDAO() {
        super(ContactSite.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }

    public Integer newContactTypeId(String site) {
        TypedQuery<Long> query = entityManager.createNamedQuery("ContactSite.findNextId", Long.class);
        query.setParameter("idsite", site);
        Long l = query.getSingleResult();

        if (l != null) {
            l += 1;
            return l.intValue();
        }

        return 1;
    }
}
